
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>5.7 分类下的话题列表 · Laravel学习-从零开发论坛系统</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="kaleozhou">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="8.html" />
    
    
    <link rel="prev" href="6.html" />
    

    
        <link rel="shortcut icon" href='../book.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../book.ico' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../book.ico'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../book.ico">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../book.ico">
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://www.kaleozhou.top" target="_blank" class="custom-link">我的博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    序言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1/1.html">
            
                <a href="../chapter1/1.html">
            
                    
                    第一章 开发环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter2/readme.html">
            
                <a href="../chapter2/readme.html">
            
                    
                    第二章 创建应用及布局
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/1.html">
            
                <a href="../chapter2/1.html">
            
                    
                    2.1 创建应用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter2/2.html">
            
                <a href="../chapter2/2.html">
            
                    
                    2.2 创建布局文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter2/3.html">
            
                <a href="../chapter2/3.html">
            
                    
                    2.3 创建首页展示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter2/4.html">
            
                <a href="../chapter2/4.html">
            
                    
                    2.4 调整样式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter3/readme.html">
            
                <a href="../chapter3/readme.html">
            
                    
                    第三章 laravel组件的使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter3/1.html">
            
                <a href="../chapter3/1.html">
            
                    
                    3.1 用户脚手架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter3/2.html">
            
                <a href="../chapter3/2.html">
            
                    
                    3.2 注册验证码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter3/3.html">
            
                <a href="../chapter3/3.html">
            
                    
                    3.3 邮箱验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter3/4.html">
            
                <a href="../chapter3/4.html">
            
                    
                    3.4 密码重置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter4/readme.html">
            
                <a href="../chapter4/readme.html">
            
                    
                    第四章 基础功能开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter4/1.html">
            
                <a href="../chapter4/1.html">
            
                    
                    4.1 个人页面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter4/2.html">
            
                <a href="../chapter4/2.html">
            
                    
                    4.2 编辑个人资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter4/3.html">
            
                <a href="../chapter4/3.html">
            
                    
                    4.3 显示个人资料
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter4/4.html">
            
                <a href="../chapter4/4.html">
            
                    
                    4.4 上传头像
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="readme.html">
            
                <a href="readme.html">
            
                    
                    第五章 帖子功能开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="1.html">
            
                <a href="1.html">
            
                    
                    5.1 帖子分类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="2.html">
            
                <a href="2.html">
            
                    
                    5.2 代码生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="3.html">
            
                <a href="3.html">
            
                    
                    5.3 生成话题骨架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="4.html">
            
                <a href="4.html">
            
                    
                    5.4 假数据填充
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="5.html">
            
                <a href="5.html">
            
                    
                    5.5 话题列表页面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="6.html">
            
                <a href="6.html">
            
                    
                    5.6 性能优化
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.7" data-path="7.html">
            
                <a href="7.html">
            
                    
                    5.7 分类下的话题列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="8.html">
            
                <a href="8.html">
            
                    
                    5.8 话题排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="9.html">
            
                <a href="9.html">
            
                    
                    5.9 用户发布的话题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter6/readme.html">
            
                <a href="../chapter6/readme.html">
            
                    
                    第六章 话题开发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter6/1.html">
            
                <a href="../chapter6/1.html">
            
                    
                    6.1 新建话题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter6/2.html">
            
                <a href="../chapter6/2.html">
            
                    
                    6.2 编辑器优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter6/3.html">
            
                <a href="../chapter6/3.html">
            
                    
                    6.3 上传图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter6/4.html">
            
                <a href="../chapter6/4.html">
            
                    
                    6.4 显示帖子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter6/5.html">
            
                <a href="../chapter6/5.html">
            
                    
                    6.5 XSS安全漏洞
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter6/6.html">
            
                <a href="../chapter6/6.html">
            
                    
                    6.6 编辑帖子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >5.7 分类下的话题列表</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><b></b>5.7 &#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><b></b>&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;</a></li><li><span class="title-icon "></span><a href="#1-&#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;"><b></b>1. &#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;</a></li><li><span class="title-icon "></span><a href="#2-&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;"><b></b>2. &#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;</a></li><li><span class="title-icon "></span><a href="#3-&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;"><b></b>3. &#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;</a></li><li><span class="title-icon "></span><a href="#&#x3000;&#x5BFC;&#x822A;&#x7684;active&#x72B6;&#x6001;"><b></b>&#x3000;&#x5BFC;&#x822A;&#x7684;Active&#x72B6;&#x6001;</a></li></ul></ul></div><a href="#57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><a name="57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;" class="anchor-navigation-ex-anchor" href="#57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;" class="plugin-anchor" href="#57-&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>5.7 &#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;</h1>
<h2 id="&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><a name="&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;" class="anchor-navigation-ex-anchor" href="#&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;" class="plugin-anchor" href="#&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5206;&#x7C7B;&#x4E0B;&#x7684;&#x8BDD;&#x9898;&#x5217;&#x8868;</h2>
<p>&#x3010;&#x8BDD;&#x9898;&#x5206;&#x7C7B;&#x3011;&#x529F;&#x80FD;&#x6709;&#x52A9;&#x4E8E;&#x8BDD;&#x9898;&#x7684;&#x5F52;&#x7C7B;&#xFF0C;&#x65B9;&#x4FBF;&#x7528;&#x6237;&#x67E5;&#x8BE2;&#x4FE1;&#x606F;&#xFF0C;&#x672C;&#x7AE0;&#x8282;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5F00;&#x53D1;&#x4E00;&#x4E0B;&#x529F;&#x80FD;</p>
<ul>
<li>&#x6839;&#x636E;&#x5206;&#x7C7B;&#x663E;&#x793A;&#x8BDD;&#x9898;&#x5217;&#x8868;</li>
<li>&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x5B9A;&#x5236;</li>
<li>&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;</li>
<li>&#x5BFC;&#x822A;&#x680F;&#x7684;&#x9009;&#x4E2D;&#x72B6;&#x6001;</li>
</ul>
<h2 id="1-&#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;"><a name="1-&#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;" class="anchor-navigation-ex-anchor" href="#1-&#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="1-&#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;" class="plugin-anchor" href="#1-&#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x6839;&#x636E;&#x5206;&#x7C7B;&#x5217;&#x8868;&#x8BDD;&#x9898;</h2>
<p>&#x8DEF;&#x7531;&#x6587;&#x4EF6;&#x65B0;&#x589E;&#x4E00;&#x884C;</p>
<pre><code>.
.
.
Route::resource(&apos;categories&apos;,&apos;CategoriesController&apos;,[&apos;only&apos;=&gt;[&apos;show&apos;]]);
.
.
.
</code></pre><p>&#x521B;&#x5EFA;&#x63A7;&#x5236;&#x5668;:</p>
<pre><code>vagrant@homestead:~/Code/kaleobbs$ php artisan make:controller CategoriesController
Controller created successfully.
</code></pre><p>&#x63A7;&#x5236;&#x5668;&#x4E2D;&#x65B0;&#x589E;&#x65B9;&#x6CD5;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim app/Http/Controllers/CategoriesController.php
</code></pre><p>&#x5185;&#x5BB9;:</p>
<pre><code>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Topic;
use App\Models\Category;

class CategoriesController extends Controller
{
    public function show(Category $category){
        //&#x8BFB;&#x53D6;&#x5206;&#x7C7B;ID&#x5173;&#x8054;&#x7684;&#x8BDD;&#x9898;&#xFF0C;&#x5E76;&#x6309;&#x6BCF;15&#x6761;&#x5206;&#x9875;
        $topics=Topic::where(&apos;category_id&apos;,$category-&gt;id)-&gt;paginate();
        //&#x4F20;&#x53C2;&#x53D8;&#x91CF;&#x8BDD;&#x9898;&#x548C;&#x5206;&#x7C7B;&#x5230;&#x6A21;&#x677F;&#x4E2D;
        return view(&apos;topics.index&apos;,compact(&apos;topics&apos;,&apos;category&apos;));
    }
}
</code></pre><p>&#x63A5;&#x4E0B;&#x6765;&#x5728;&#x8BDD;&#x9898;&#x5217;&#x8868;&#x4E2D;&#x4E3A;&#x5206;&#x7C7B;&#x6DFB;&#x52A0;&#x8DEF;&#x7531;&#x8FDE;&#x63A5;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim resources/views/topics/_topic_list.blade.php
</code></pre><p>&#x4FEE;&#x6539;&#x8FD9;&#x4E00;&#x884C;&#x5185;&#x5BB9;:</p>
<pre><code>.
.
.
              &lt;a class=&quot;text-secondary&quot; href=&quot;{{route(&apos;categories.show&apos;,$topic-&gt;category_id)}}&quot; title=&quot;{{ $topic-&gt;category-&gt;name }}&quot;&gt;
.
.
.
</code></pre><p>&#x5B9A;&#x5236;&#x5217;&#x8868;&#x9875;&#x9762;&#x6A21;&#x677F;&#xFF0C;&#x7528;&#x4EE5;&#x8868;&#x793A;&#x5F53;&#x524D;&#x6240;&#x5728;&#x7684;&#x5206;&#x7C7B;&#xFF0C;&#x4E00;&#x6B21;&#x6765;&#x4E0E;&#x3010;&#x6240;&#x6709;&#x5217;&#x8868;&#x9875;&#x9762;&#x3011;&#x533A;&#x5206;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim resources/views/topics/index.blade.php
</code></pre><p>&#x5185;&#x5BB9;:</p>
<pre><code>@extends(&apos;layouts.app&apos;)

@section(&apos;title&apos;, &apos;&#x8BDD;&#x9898;&#x5217;&#x8868;&apos;)

@section(&apos;content&apos;)

&lt;div class=&quot;row mb-5&quot;&gt;
  &lt;div class=&quot;col-lg-9 col-md-9 topic-list&quot;&gt;
    @if (isset($category))
    &lt;div class=&quot;alert alert-info&quot; role=&quot;alert&quot;&gt;
        {{$category-&gt;name}} : {{$category-&gt;description}}
    &lt;/div&gt;
    @endif
    &lt;div class=&quot;card &quot;&gt;
      &lt;div class=&quot;card-header bg-transparent&quot;&gt;
        &lt;ul class=&quot;nav nav-pills&quot;&gt;
          &lt;li class=&quot;nav-item&quot;&gt;&lt;a class=&quot;nav-link active&quot; href=&quot;#&quot;&gt;&#x6700;&#x540E;&#x56DE;&#x590D;&lt;/a&gt;&lt;/li&gt;
          &lt;li class=&quot;nav-item&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;#&quot;&gt;&#x6700;&#x65B0;&#x53D1;&#x5E03;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;

      &lt;div class=&quot;card-body&quot;&gt;
        {{-- &#x8BDD;&#x9898;&#x5217;&#x8868; --}}
        @include(&apos;topics._topic_list&apos;, [&apos;topics&apos; =&gt; $topics])
        {{-- &#x5206;&#x9875; --}}
        &lt;div class=&quot;mt-5&quot;&gt;
          {!! $topics-&gt;appends(Request::except(&apos;page&apos;))-&gt;render() !!}
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div class=&quot;col-lg-3 col-md-3 sidebar&quot;&gt;
    @include(&apos;topics._sidebar&apos;)
  &lt;/div&gt;
&lt;/div&gt;

@endsection
</code></pre><p>&#x67E5;&#x770B;&#x6548;&#x679C;:
<img src="http://images.kaleozhou.top/5.7-01.png" alt="5.7-01.png">
&#x4FEE;&#x6539;css&#x6837;&#x5F0F;</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim resources/sass/app.scss
</code></pre><p>&#x4FEE;&#x6539;&#x5982;&#x4E0B;:</p>
<pre><code>/* Topic Index Page */
.topics-index-page, .categories-show-page {
</code></pre><h2 id="2-&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;"><a name="2-&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;" class="anchor-navigation-ex-anchor" href="#2-&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="2-&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;" class="plugin-anchor" href="#2-&#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x5217;&#x8868;&#x9875;&#x9762;&#x6807;&#x9898;&#x7684;&#x5B9A;&#x5236;</h2>
<p>&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x5206;&#x7C7B;&#x8BDD;&#x9898;&#x5217;&#x8868;&#x9875;&#x9762;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x9875;&#x9762;&#x7684;&#x6807;&#x9898;&#x91CC;&#x9762;&#x6709;&#x5F53;&#x524D;&#x7684;&#x5206;&#x7C7B;&#x540D;&#x79F0;:
<img src="http://images.kaleozhou.top/5.7-02.png" alt="5.7-02.png">
&#x5982;&#x56FE;&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#xFF0C;&#x8BDD;&#x9898;&#x5217;&#x8868;&#x663E;&#x793A;&#x4E3A;&#x5206;&#x7C7B;&#x7684;&#x540D;&#x79F0;
&#x4FEE;&#x6539;&#x5217;&#x8868;&#x9875;&#x9762;&#x6A21;&#x677F;&#xFF0C;&#x4F7F;&#x7528;&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#x6765;&#x5B9A;&#x5236;title&#x533A;&#x5757;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim resources/views/topics/index.blade.php
</code></pre><p>&#x4FEE;&#x6539;&#x8FD9;&#x4E00;&#x884C;&#x5982;&#x4E0B;&#x5982;&#x4E0B;:</p>
<pre><code>.
.
.
@section(&apos;title&apos;, isset($category) ? $category-&gt;name : &apos;&#x8BDD;&#x9898;&#x5217;&#x8868;&apos;)
.
.
.
</code></pre><p>&#x5237;&#x65B0;&#x67E5;&#x770B;&#x6548;&#x679C;:
<img src="http://images.kaleozhou.top/5.7-03.png" alt="5.7-03.png"></p>
<h2 id="3-&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;"><a name="3-&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;" class="anchor-navigation-ex-anchor" href="#3-&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="3-&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;" class="plugin-anchor" href="#3-&#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x589E;&#x52A0;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;</h2>
<p>&#x63A5;&#x4E0B;&#x91CC;&#x65B0;&#x589E;&#x9876;&#x90E8;&#x5BFC;&#x822A;&#x680F;&#xFF0C;&#x8BA9;&#x7528;&#x6237;&#x80FD;&#x66F4;&#x52A0;&#x65B9;&#x4FBF;&#x7684;&#x67E5;&#x770B;&#x5206;&#x7C7B;&#x4FE1;&#x606F;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) vim resources/views/layouts/_header.blade.php
</code></pre><p>&#x5185;&#x5BB9;:</p>
<pre><code>.
.
.
&lt;!-- Left Side Of Navbar --&gt;
&lt;ul class=&quot;navbar-nav mr-auto&quot;&gt;
&lt;li class=&quot;nav-item active&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;topics.index&apos;) }}&quot;&gt;&#x8BDD;&#x9898;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 1) }}&quot;&gt;&#x5206;&#x4EAB;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 2) }}&quot;&gt;&#x6559;&#x7A0B;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 3) }}&quot;&gt;&#x95EE;&#x7B54;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 4) }}&quot;&gt;&#x516C;&#x544A;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
.
.
.
</code></pre><p>&#x67E5;&#x770B;&#x6548;&#x679C;:
<img src="http://images.kaleozhou.top/5.7-04.png" alt="5.7-04.png"></p>
<h2 id="&#x3000;&#x5BFC;&#x822A;&#x7684;active&#x72B6;&#x6001;"><a name="&#x3000;&#x5BFC;&#x822A;&#x7684;active&#x72B6;&#x6001;" class="anchor-navigation-ex-anchor" href="#&#x3000;&#x5BFC;&#x822A;&#x7684;active&#x72B6;&#x6001;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x3000;&#x5BFC;&#x822A;&#x7684;active&#x72B6;&#x6001;" class="plugin-anchor" href="#&#x3000;&#x5BFC;&#x822A;&#x7684;active&#x72B6;&#x6001;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x3000;&#x5BFC;&#x822A;&#x7684;Active&#x72B6;&#x6001;</h2>
<p>&#x5BFC;&#x822A;&#x7684;&#x9009;&#x4E2D;&#x72B6;&#x6001;&#x6837;&#x5F0F;&#x901A;&#x8FC7;&#x6DFB;&#x52A0;CSS&#x7C7B;&#x9009;&#x62E9;&#x5668;active&#x6765;&#x5B9E;&#x73B0;&#xFF0C;&#x5B89;&#x88C5;&#x8F85;&#x52A9;&#x7C7B;&#x5E93;hieu-le/active</p>
<pre><code>vagrant@homestead:~/Code/kaleobbs$ composer require &quot;hieu-le/active:~3.5&quot;
</code></pre><p>&#x5B89;&#x88C5;&#x5B8C;&#x6210;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x4F7F;&#x7528;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim resources/views/layouts/_header.blade.php
</code></pre><p>&#x4FEE;&#x6539;&#x4E3A;:</p>
<pre><code>.
.
.
&lt;!-- Left Side Of Navbar --&gt;
&lt;ul class=&quot;navbar-nav mr-auto&quot;&gt;
&lt;li class=&quot;nav-item {{ active_class(if_route(&apos;topics.index&apos;)) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;topics.index&apos;) }}&quot;&gt;&#x8BDD;&#x9898;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ active_class((if_route(&apos;categories.show&apos;) &amp;&amp; if_route_param(&apos;category&apos;, 1))) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 1) }}&quot;&gt;&#x5206;&#x4EAB;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ active_class((if_route(&apos;categories.show&apos;) &amp;&amp; if_route_param(&apos;category&apos;, 2))) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 2) }}&quot;&gt;&#x6559;&#x7A0B;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ active_class((if_route(&apos;categories.show&apos;) &amp;&amp; if_route_param(&apos;category&apos;, 3))) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 3) }}&quot;&gt;&#x95EE;&#x7B54;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ active_class((if_route(&apos;categories.show&apos;) &amp;&amp; if_route_param(&apos;category&apos;, 4))) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 4) }}&quot;&gt;&#x516C;&#x544A;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
.
.
.
</code></pre><p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x5F00;&#x8D77;&#x6765;&#x5F88;&#x590D;&#x6742;&#xFF0C;&#x592A;&#x591A;&#x91CD;&#x590D;&#x4EE3;&#x7801;&#xFF0C;&#x6211;&#x4EEC;&#x6765;&#x4F18;&#x5316;&#x4E00;&#x4E0B;&#xFF0C;&#x5C06;&#x91CD;&#x590D;&#x4EE3;&#x7801;&#x62BD;&#x51FA;&#x6765;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x8F85;&#x52A9;&#x51FD;&#x6570;&#x91CC;&#x9762;:</p>
<pre><code>&#x279C; kaleo@zhou  ~/Code/kaleobbs git:(master) &#x2717; vim app/helpers.php
</code></pre><p>&#x5185;&#x5BB9;:</p>
<pre><code>&lt;?php
/** =============================================================================
 * @name helpers.php
 * @date date 2019&#x5E74;03&#x6708;24&#x65E5; &#x661F;&#x671F;&#x65E5; 17&#x65F6;06&#x5206;58&#x79D2;
 * @author kaleo &lt;kaleo1990@hotmail.com&gt;
 * @package
 * =============================================================================
 */
function route_class(){
    return str_replace(&apos;.&apos;,&apos;-&apos;,Route::currentRouteName());
}

function category_nav_active($category_id){
    return active_class((if_route(&apos;categories.show&apos;) &amp;&amp; if_route_param(&apos;category&apos;, $category_id)));
}
</code></pre><p>&#x91CD;&#x65B0;&#x4FEE;&#x6539;&#x6A21;&#x677F;&#x91CC;&#x7684;&#x8C03;&#x7528;:</p>
<pre><code>.
.
.
&lt;!-- Left Side Of Navbar --&gt;
&lt;ul class=&quot;navbar-nav mr-auto&quot;&gt;
&lt;li class=&quot;nav-item {{ active_class(if_route(&apos;topics.index&apos;)) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;topics.index&apos;) }}&quot;&gt;&#x8BDD;&#x9898;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ category_nav_active(1)}}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 1) }}&quot;&gt;&#x5206;&#x4EAB;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ category_nav_active(2) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 2) }}&quot;&gt;&#x6559;&#x7A0B;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ category_nav_active(3) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 3) }}&quot;&gt;&#x95EE;&#x7B54;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;nav-item {{ category_nav_active(4) }}&quot;&gt;&lt;a class=&quot;nav-link&quot; href=&quot;{{ route(&apos;categories.show&apos;, 4) }}&quot;&gt;&#x516C;&#x544A;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
.
.
.
</code></pre><p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x8BB2;&#x89E3;&#x4E00;&#x4E0B;active_class&#x51FD;&#x6570;&#x7684;&#x7528;&#x6CD5;&#xFF0C;&#x6B64;&#x51FD;&#x6570;&#x7684;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;:</p>
<pre><code>/**
 * &#x5982;&#x679C; $condition &#x4E0D;&#x4E3A; True &#x5373;&#x4F1A;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32; `active`
 *
 * @param        $condition
 * @param string $activeClass
 * @param string $inactiveClass
 *
 * @return string
 */
function active_class($condition, $activeClass = &apos;active&apos;, $inactiveClass = &apos;&apos;)
</code></pre><p>&#x5982;&#x679C;&#x4F20;&#x53C2;&#x6EE1;&#x8DB3;&#x6307;&#x5B9A;&#x6761;&#x4EF6; ($condition) &#xFF0C;&#x6B64;&#x51FD;&#x6570;&#x5C06;&#x8FD4;&#x56DE; $activeClass&#xFF0C;&#x5426;&#x5219;&#x8FD4;&#x56DE; $inactiveClass&#x3002;</p>
<p>&#x6B64;&#x6269;&#x5C55;&#x5305;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x6279;&#x51FD;&#x6570;&#x8BA9;&#x6211;&#x4EEC;&#x66F4;&#x65B9;&#x4FBF;&#x7684;&#x8FDB;&#x884C; $condition &#x5224;&#x65AD;&#xFF1A;</p>
<ol>
<li>if_route () - &#x5224;&#x65AD;&#x5F53;&#x524D;&#x5BF9;&#x5E94;&#x7684;&#x8DEF;&#x7531;&#x662F;&#x5426;&#x662F;&#x6307;&#x5B9A;&#x7684;&#x8DEF;&#x7531;&#xFF1B;</li>
<li>if_route_param () - &#x5224;&#x65AD;&#x5F53;&#x524D;&#x7684; url &#x6709;&#x65E0;&#x6307;&#x5B9A;&#x7684;&#x8DEF;&#x7531;&#x53C2;&#x6570;&#x3002;</li>
<li>if_query () - &#x5224;&#x65AD;&#x6307;&#x5B9A;&#x7684; GET &#x53D8;&#x91CF;&#x662F;&#x5426;&#x7B26;&#x5408;&#x8BBE;&#x7F6E;&#x7684;&#x503C;&#xFF1B;</li>
<li>if_uri () - &#x5224;&#x65AD;&#x5F53;&#x524D;&#x7684; url &#x662F;&#x5426;&#x6EE1;&#x8DB3;&#x6307;&#x5B9A;&#x7684; url&#xFF1B;</li>
<li>if_route_pattern () - &#x5224;&#x65AD;&#x5F53;&#x524D;&#x7684;&#x8DEF;&#x7531;&#x662F;&#x5426;&#x5305;&#x542B;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;&#xFF1B;</li>
<li>if_uri_pattern () - &#x5224;&#x65AD;&#x5F53;&#x524D;&#x7684; url &#x662F;&#x5426;&#x542B;&#x6709;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;&#xFF1B;</li>
</ol>
<p>&#x67E5;&#x770B;&#x6548;&#x679C;:
<img src="http://images.kaleozhou.top/5.7-06.gif" alt="5.7-06.gif"></p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; kaleozhou 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2019-05-20 16:13:51
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="6.html" class="navigation navigation-prev " aria-label="Previous page: 5.6 性能优化">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="8.html" class="navigation navigation-next " aria-label="Next page: 5.8 话题排序">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"5.7 分类下的话题列表","level":"1.6.7","depth":2,"next":{"title":"5.8 话题排序","level":"1.6.8","depth":2,"path":"chapter5/8.md","ref":"chapter5/8.md","articles":[]},"previous":{"title":"5.6 性能优化","level":"1.6.6","depth":2,"path":"chapter5/6.md","ref":"chapter5/6.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","donate","sharing-plus","anchor-navigation-ex","tbfed-pagefooter","favicon"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy kaleozhou 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"github":{"url":"https://gitee.com/kaleozhou"},"splitter":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"http://images.kaleozhou.top/zanshang.png","alipayText":" ","button":"赞赏","title":"","wechat":"","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{"shortcut":"./book.ico","bookmark":"./book.ico","appleTouch":"./book.ico","appleTouchMore":{"120x120":"./book.ico","180x180":"./book.ico"}},"github-buttons":{"buttons":[{"user":"kaleozhou","repo":"guanwang","type":"star","size":"small","count":true}]},"expandable-chapters-small":{},"sharing":{"qq":true,"all":["weibo","qq","qzone"],"douban":true,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","author":"kaleozhou","pdf":{"pageBreaksBefore":"/","paperSize":"a4","margin":{"right":30,"left":30,"top":30,"bottom":50},"fontSize":18,"pageSize":"a4","fontFamily":"Arial","doc":true,"chapterMark":"pagebreak","pageNumbers":true},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Laravel学习-从零开发论坛系统","language":"zh-hans","links":{"sidebar":{"我的博客":"http://www.kaleozhou.top"}},"gitbook":"3.2.3","description":"laravel框架开发论坛系统"},"file":{"path":"chapter5/7.md","mtime":"2019-05-20T08:13:51.931Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-25T02:56:39.861Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

